﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using StockTrader.DAL.IDAL;
using StockTrader.BusinessService.DataContract;
using StockTrader.DAL.MSSQLHelper;

namespace StockTrader.DAL.SQLserver
{
    public class Document : IDocument
    {
/*
                private SqlConnection _internalConnection;
                private SqlTransaction _internalADOTransaction = null;
        
                public void BeginADOTransaction()
                {
                    if (_internalConnection.State != System.Data.ConnectionState.Open)
                        _internalConnection.Open();
                    _internalADOTransaction = _internalConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                }
                public void RollBackTransaction()
                {
                    _internalADOTransaction.Rollback();
                    _internalADOTransaction = null;
                }
                public void CommitADOTransaction()
                {
                    _internalADOTransaction.Commit();
                    _internalADOTransaction = null;
                }
                public void Open(string connString)
                {
                    if (_internalConnection == null)
                        _internalConnection = new SqlConnection(connString);
                    if (_internalConnection.State != ConnectionState.Open)
                        _internalConnection.Open();
                }
                public void Close()
                {
                    if (_internalConnection != null && _internalConnection.State != System.Data.ConnectionState.Closed)
                        _internalConnection.Close();
                }
        
                #region SQL string
                private const string SQL_DOCUMENT_INSERT = "INSERT INTO COMPANY_DOCS(NAME, DESCRIPTION, DOCTYPE, COMPANYCODE, PERIOD, YEAR, ISSUER, PUBLISHED, LASTUPDATED, FILEPATH, STATUS) VALUES (@NAME, @DESCRIPTION, @DOCTYPE, @COMPANYCODE, @PERIOD, @YEAR, @ISSUER, @PUBLISHED, @LASTUPDATED, @FILEPATH, @STATUS); SELECT ID=@@IDENTITY;";
                private const string SQL_DOCUMENT_DELETE = "DELETE FROM COMPANY_DOCS WHERE ID=@ID";
                #endregion
        
                #region Parameters
                private const string PARM_ID = "@ID";
                private const string PARM_NAME = "@NAME";
                private const string PARM_DESCRIPTION = "@DESCRIPTION";
                private const string PARM_DOCTYPE = "@DOCTYPE";
                private const string PARM_COMPANYCODE = "@COMPANYCODE";
                private const string PARM_PERIOD = "@PERIOD";
                private const string PARM_YEAR = "@YEAR";
                private const string PARM_ISSUER = "@ISSUER";
                private const string PARM_PUBLISHED = "@PUBLISHED";
                private const string PARM_LASTUPDATE = "@LASTUPDATED";
                private const string PARM_FILEPATH = "@FILEPATH";
                private const string PARM_STATUS = "@STATUS";
                #endregion
        
                #region IDocument Members
                
                public List<DocumentUI> GetDocument()
                {
                    throw new NotImplementedException();
                }
        
                public List<DocumentUI> GetDocumentByName(string name)
                {
                    throw new NotImplementedException();
                }
        
                public List<DocumentUI> GetDocumentByYear(int year)
                {
                    throw new NotImplementedException();
                }
        
                public List<DocumentUI> GetDocumentByPeriod(int year, int period)
                {
                    throw new NotImplementedException();
                }
        
                public List<DocumentUI> GetDocumentByStandard(int StandardId)
                {
                    throw new NotImplementedException();
                }
        
                public int InsertDoc(DocumentData item)
                {
                    try
                    {
                        SqlParameter[] parms = new SqlParameter[] {
                            new SqlParameter(PARM_NAME, SqlDbType.NVarChar),
                            new SqlParameter(PARM_DESCRIPTION, SqlDbType.NText),
                            new SqlParameter(PARM_DOCTYPE, SqlDbType.Int),
                            new SqlParameter(PARM_COMPANYCODE, SqlDbType.NVarChar),
                            new SqlParameter(PARM_PERIOD, SqlDbType.Int),
                            new SqlParameter(PARM_YEAR, SqlDbType.Int),
                            new SqlParameter(PARM_ISSUER, SqlDbType.NVarChar),
                            new SqlParameter(PARM_PUBLISHED, SqlDbType.DateTime),
                            new SqlParameter(PARM_LASTUPDATE, SqlDbType.DateTime),
                            new SqlParameter(PARM_FILEPATH, SqlDbType.NVarChar),
                            new SqlParameter(PARM_STATUS, SqlDbType.Int)};
                        parms[0].Value = item.Name;
                        parms[1].Value = item.Description;
                        parms[2].Value = item.DocType;
                        parms[3].Value = item.CompanyCode;
                        parms[4].Value = item.Period;
                        parms[5].Value = item.Year;
                        parms[6].Value = item.Issuer;
                        parms[7].Value = item.Published;
                        parms[8].Value = item.LastUpdated;
                        parms[9].Value = item.FilePath;
                        parms[10].Value = item.Status;
                        return SQLHelper.ExecuteScalar(_internalConnection, _internalADOTransaction, CommandType.Text, SQL_DOCUMENT_INSERT, parms);
                    }
                    catch
                    {
                        throw;
                    }
                }
        
                public void UpdateDoc(DocumentData item)
                {
                    throw new NotImplementedException();
                }
        
                public void DeleteDoc(int id)
                {
                    throw new NotImplementedException();
                }
        
                #endregion*/
        
    }
}
